<template>
	<div class="row">
		<h2 v-show="listInfo.isFirst">欢迎使用</h2>
		<h2 v-show="listInfo.isLoading">加载中....</h2>
		<h2 v-show="listInfo.errMsg">{{listInfo.errMsg}}</h2>
		<!-- 展示列表 -->
		<div v-show="listInfo.users.length" v-for="u in listInfo.users" :key="u.login" class="card">
			<a :href="u.html_url" target="_blank">
				<img :src="u.avatar_url" style='width: 100px'/>
			</a>
			<p class="card-text">{{u.login}}</p>
		</div>
	</div>
</template>

<script>
	export default {
		name:'List',
		data() {
			return {
				listInfo:{
					users:[], //用户列表
					isLoading:false, //是否处于加载中
					isFirst:true, //是否初次显示，（改过一次就不再改了）
					errMsg:'' //错误信息
				}
			}
		},
		methods:{
			saveUsers(listObj){
				console.log(listObj)
				this.listInfo = {...this.listInfo,...listObj}
			}
		},
		mounted(){
			this.$bus.$on('user-list',this.saveUsers)
		},
		beforeDestroy(){
			this.$bus.$off('user-list')
		}
	}
</script>

<style scoped>
.album {
  min-height: 50rem; /* Can be removed; just added for demo purposes */
  padding-top: 3rem;
  padding-bottom: 3rem;
  background-color: #f7f7f7;
}

.card {
  float: left;
  width: 33.333%;
  padding: .75rem;
  margin-bottom: 2rem;
  border: 1px solid #efefef;
  text-align: center;
}

.card > img {
  margin-bottom: .75rem;
  border-radius: 100px;
}

.card-text {
  font-size: 85%;
}

</style>